#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#define maxn 100

/*
 * 判断a是否合题意
 * a是否是可能出现的
 * a不可能出现则返回1
 */
bool find(int a, int cur)
{
	if (a == 1)
		return false;
	if (cur > 100)
		return true;
	int tmp = find(a, cur + 1);
	if (a % cur == 0)
		return find(a / cur, cur + 1) && tmp;
	return tmp;
}

/*如果发现冲突则返回1*/
bool judge(int a, int b, int cur)
{
	if (a == 1 && b == 1)
		return false;
	if (cur > 100)
		return true;
	int mod_a = a % cur, mod_b = b % cur;
	int tmp1 = 0, tmp2 = 0, tmp3 = 0;
	if (!mod_a)
		tmp1 = judge(a / cur, b, cur + 1);
	if (!mod_b)
		tmp2 = judge(a, b / cur, cur + 1);
	tmp3 = judge(a, b, cur + 1);
	if (!mod_a && !mod_b)
	{
		return tmp1 && tmp2 && tmp3;
	}

	if (!mod_a)
		return tmp1 && tmp3;
	if (!mod_b)
		return tmp2 && tmp3;
	return tmp3;
}

int main()
{
	int m = 0, n = 0;
	while (scanf("%d%d", &m, &n) != EOF)
	{

		if (m < n) /*keep m >= n*/
		{
			int tmp = m;
			m = n;
			n = tmp;
		}

		int tmp1 = find(m, 2);
		int tmp2 = find(n, 2);
		int tmp3 = judge(m, n, 2);
		if (!(tmp1 || tmp2 || tmp3)) /*m,n两数均合法,输出大者*/
			printf("%d\n", m);
		else if (tmp2) /*若小者不合法,直接输出大者*/
			printf("%d\n", m);
		else
			printf("%d\n", n); /*否则输出小者*/
	}
	return 0;
}